import { Component } from '@angular/core';
import {App, IonicPage, NavController, NavParams} from 'ionic-angular';
import {GOODS} from "../../api/goods-api";
import {PageParam} from "../../api/api.service";
import {USER} from "../../service/user.service";
import {CheckStandModel} from "../../model/checkstand.model";
import {ROUTER} from "../../service/router.service";
import {LocalStorage} from "../../utils/localstorage.utils";

/**
 * Generated class for the MyRentPage page.
 *
 * See http://ionicframework.com/docs/components/#navigation for more info
 * on Ionic pages and navigation.
 */
@IonicPage()
@Component({
  selector: 'page-my-rent',
  templateUrl: 'my-rent.html',
})
export class MyRentPage {
  pageParam:PageParam;
  hasMore:boolean = true;
  orderList = [];

  constructor(public GOODS:GOODS,public ls:LocalStorage,public USER: USER,public app:App, public ROUTER: ROUTER) {
  }

  ionViewDidLoad() {
    document.title='我的租赁';
    console.log('ionViewDidLoad MyRentPage');
    this.doRefresh();
  }
  pay(v){
    let checkstand = new CheckStandModel(v.orderNo, v.title, v.payMoney, v.id,ROUTER.MYRENT)
    this.ls.setObject('checkstand', checkstand);
    this.ROUTER.go(ROUTER.CHECK);
  }
  cancleOrder(item){
    this.GOODS.cancelRentOrder(item.id,v=>{
      this.USER.toast(v)
    })
  }
  doRefresh(refresher?) {
    this.pageParam = new PageParam()
    this.GOODS.getRentOrderList(v => {
      this.orderList = v.content
      this.hasMore = !v.last;
      if (refresher) {
        refresher.complete();
      }
    },this.pageParam);
  }

  get canLoadMore():boolean {
    return this.hasMore;
  }

  doInfinite(infiniteScroll) {
    ++this.pageParam.page;
    this.GOODS.getRentOrderList(v => {
      this.hasMore = !v.last;
      this.orderList = this.orderList.concat(v.content);
      infiniteScroll.complete();
    },this.pageParam);
  }


}
